layui.use(['table', 'form', 'laydate', 'laytpl', 'element'], function() {
	var table = layui.table;
	var form = layui.form,
		$ = layui.jquery,
		laydate = layui.laydate,
		laytpl = layui.laytpl,
		element = layui.element;

	//加载阶段下拉框
	loadstage("selschooltype", form);

	//根据阶段加载学校，年级下拉框
	form.on('select(selschooltype)', function(data) {
		//年级下拉框
		loadgrade(data.value, "selgradename", form);
		//学校下拉框
		loadSchool(data.value, "selschool", form);

	});

	/*测评时间动态加载*/
	$.ajax({
		type: 'get',
		url: '../sysunifiedmanagement/getperiod',
		datatype: 'json',
		success: function(timedate) {
			if(timedate.code == 10001) {
				var str = "";
				for(var i = 0; i < timedate.count; i++) {
					str += '<option value=' + timedate.data[i].starTime + "/" + timedate.data[i].endTime + '>' + timedate.data[i].starTime + '/' + timedate.data[i].endTime + '</option>';
				}
				$("#selchecktime").append(str);
				form.render("select");
			} else {
				layer.msg("测试时间获取失败");
			}
		}
	});

	/*动态加载测试报告类型下拉框*/
	$.ajax({
		type: 'get',
		url: '../json/testReportType.json',
		datatype: 'json',
		success: function(typedate) {
			if(typedate.code == 0) {
				var str = "";
				for(var i = 0; i < typedate.count; i++) {
					str += '<option value=' + typedate.data[i].name + '>' + typedate.data[i].name + '</option>';
				}
				$("#testreporttype").append(str);
				form.render("select");
			} else {
				layer.msg("测试报告类型获取失败");
			}
		}
	});

	/*点击测试报告类型筛选表格*/
	form.on('select(testreporttype)', function(data) {
		var reporttype = data.value;
		if(reporttype == 00) {
			reporttype = "";
		}

		table.render({
			elem: '#tabgradeeva',
			url: '../sysevaluationresult/getgradeevaresult?reporttype=' + reporttype,
			title: '年级测评统计分析报告',
			height: "full-110",
			skin: 'line',
			even: true,
			cols: [
				[{
					type: 'numbers',
					title: '序号',
					align: 'center',
					width: '5%'
				}, {
					field: 'checkname',
					title: '测评报告类型',
					align: 'center',
					width: '30%'
				}, {
					field: 'checktime',
					title: '测评时间',
					align: 'center',
					width: '15%'
				}, {
					field: 'gradename',
					title: '年级',
					align: 'center',
					width: '15%'
				}, {
					field: 'schoolName',
					title: '所属学校',
					align: 'center',
					width: '20%'
				}, {
					title: '操作',
					toolbar: '#barDemo',
					align: 'center',
					width: '15%'
				}]
			],
			page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF',
			}
		});

	});

	/*点击查询按钮对测试报告进行筛选*/
	$("#btnselperevalua").click(function() {
		var reporttype = $("#testreporttype").val();
		var checktime = $("#selchecktime").val();
		var gradename = $("#selgradename").val();
		var schoolid = $("#selschool").val();
		if(schoolid == 00 || schoolid == null) {
			schoolid = "";
		}
		if(checktime == 00) {
			checktime = "";
		}
		if(gradename == 00) {
			gradename = "";
		}
		table.render({
			elem: '#tabgradeeva',
			url: '../sysevaluationresult/getgradeevaresult?reporttype=' + reporttype + "&checktime=" + checktime + "&schoolid=" + schoolid + "&gradename=" + gradename,
			title: '年级测评统计分析报告',
			height: "full-110",
			skin: 'line',
			even: true,
			cols: [
				[{
					type: 'numbers',
					title: '序号',
					align: 'center',
					width: '5%'
				}, {
					field: 'gradename',
					title: '年级',
					align: 'center',
					width: '20%'
				}, {
					field: 'checkname',
					title: '测评报告类型',
					align: 'center',
					width: '35%'
				}, {
					field: 'checktime',
					title: '测评时间',
					align: 'center',
					width: '20%'
				}, {
					title: '操作',
					toolbar: '#barDemo',
					align: 'center',
					width: '20%'
				}]
			],
			page: {
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
				groups: 5,
				limit: 10,
				limits: [10, 20, 30, 40, 50],
				theme: '#1E9FFF',
			}
		});

	});

	//监听行工具事件
	table.on('tool(tabgradeeva)', function(obj) {
		var classdata = obj.data;
		var classchecktype = classdata.checkname;
		if(obj.event === 'analysis') {
			var para = "checktypeid=" + classdata.checktypeid;
			para += "&checktime=" + classdata.checktime;
			para += "&gradename=" + classdata.gradename;
			para += "&schoolname=" + classdata.schoolName;

			if(classchecktype.indexOf("MHT") >= 0) {
				var index = layer.open({
					type: 2,
					title: '班级MHT统计结果',
					area: ['830px', '95%'],
					shade: 0.8,
					maxmin: true,
					content: ['../evaluationResult/GradeMHTCheckResultStatis.jsp?' + para, 'yes'],
					cancel: function() {}
				});
				layer.full(index);

			} else if(classchecktype.indexOf("EPQ") >= 0) {
				var index = layer.open({
					type: 2,
					title: '班级EPQ统计结果',
					area: ['830px', '95%'],
					shade: 0.8,
					maxmin: true,
					content: ['../evaluationResult/GradeEPQCheckResultStatis.jsp?' + para, 'yes'],
					cancel: function() {}
				});
				layer.full(index);
			}

		} else if(obj.event === 'printing') {
			var para = "checktypeid=" + classdata.checktypeid;
			para += "&checktime=" + classdata.checktime;
			para += "&gradename=" + classdata.gradename;
			para += "&schoolname=" + classdata.schoolName;

			if(classchecktype.indexOf("MHT") >= 0) {
				var index = layer.open({
					type: 2,
					title: '年级(MHT)的测试报告结果打印',
					area: ['830px', '95%'],
					shade: 0.8,
					maxmin: true,
					content: ['../evaluationResult/GradeMHTCheckStatisPrinter.jsp?' + para, 'yes'],
					cancel: function() {}
				});
				layer.full(index);
			} else if(classchecktype.indexOf("EPQ") >= 0) {
				var index = layer.open({
					type: 2,
					title: '年级(EPQ)的测试报告结果打印',
					area: ['830px', '95%'],
					shade: 0.8,
					maxmin: true,
					content: ['../evaluationResult/GradeEPQCheckStatisPrinter.jsp?' + para, 'yes'],
					cancel: function() {}
				});
				layer.full(index);
			}
		}
	});
});